<script>
export default {
	globalData: {
		is_flag: true ,//跳转开关
		isAuthAgain: false,
	},
	onLaunch: function() {
		// #ifdef MP-WEIXIN
		// 获取用户信息
		const updateManager = uni.getUpdateManager();

		updateManager.onCheckForUpdate(function(res) {
			// 请求完新版本信息的回调
			console.log(res.hasUpdate);
		});

		updateManager.onUpdateReady(function(res) {
			uni.showModal({
				title: '更新提示',
				content: '新版本已经准备好，是否重启应用？',
				success(res) {
					if (res.confirm) {
						// 新的版本已经下载好，调用 applyUpdate 应用新版本并重启
						updateManager.applyUpdate();
					}
				}
			});
		});

		updateManager.onUpdateFailed(function(res) {
			// 新的版本下载失败
		});
		// #endif
		// #ifdef APP-PLUS
		let type;
		if (uni.getSystemInfoSync().platform === 'android') {
			type = '0';
		} else {
			type = '1';
		}
		// let openURL = type === '1' ? 'itms-apps://apps.apple.com/cn/app/%E5%A4%96%E8%BF%90%E5%90%AF%E8%88%AA/id1476218508' : 'https://nfp.y2t.com/apk/运必达.apk';
		let openURL = type === '1' ? 'https://apps.apple.com/cn/app/%E8%BF%90%E5%BF%85%E8%BE%BE/id1632128722' : 'https://nfp.y2t.com/apk/运必达.apk';
		let userPlatform = type === '1' ? 'ios' : 'Android';
		this.version = 'V' + plus.runtime.version;
		this.wxRequest({
			url: `${this.API}/version/check?userVersion=` + this.version + '&userPlatform=' + userPlatform,
			method: 'POST',
			success: res => {
				if (res.data.code == 0) {
					console.log('version', this.version);
					let version = this.version;
					console.log('版本号：' + res.data.data.version);
					if (version != res.data.data.version) {
						if (res.data.data.whether == '1') {
							uni.showModal({
								title: '提示',
								content: '发现有新版本，请立即更新',
								showCancel: false,
								confirmText: '立即更新',
								success: function(res) {
									if (res.confirm) {
										plus.runtime.openURL(openURL);
										plus.runtime.quit();
									}
								}
							});
						} else {
							uni.showModal({
								title: '提示',
								content: '有新版本可升级',
								confirmText: '立即升级',
								cancelText: '稍后升级',
								success: function(res) {
									if (res.confirm) {
										plus.runtime.openURL(openURL);
									} else if (res.cancel) {
										// console.log('用户点击取消');
									}
								}
							});
						}
					}
				}
			}
		});
		// #endif
		console.log('接收2222参数 ', uni.getStorageSync(this.DATA_KEY.userInfo).phoneNumber);
		if (uni.getStorageSync(this.DATA_KEY.userInfo).phoneNumber) {
			this.wxRequest({
				url: `${this.API}/user/myInfo`,
				method: 'POST',
				data: {
					phoneNumber: uni.getStorageSync(this.DATA_KEY.userInfo).phoneNumber
				},
				success: res => {
					const userInfo = uni.getStorageSync(this.DATA_KEY.userInfo);
					userInfo.state = res.data.data.state;
					userInfo.plateNo = res.data.data.plateNo;
					userInfo.lbsauthState = res.data.data.lbsauthState;
					uni.setStorageSync(this.DATA_KEY.userInfo, userInfo);
				}
			});
		}
	},
	onShow: function(options) {
		// console.log("接收参数 ",options)
	
	},
	onHide: function() {
	}
};
</script>

<style>
/*每个页面公共css */
page {
	display: flex;
	flex-direction: column;
	box-sizing: border-box;
	background-color: #f6f6f6;
	font-size: 30rpx;
}

.reset-button {
  padding: 0;
  margin: 0;
  font-size: inherit;
  background-color: transparent;
  color: inherit;
  position: relative;
  border: 0rpx;
  /* #ifndef APP-NVUE */
  display: flex;
  /* #endif */
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  text-align: center;
  text-decoration: none;
  white-space: nowrap;
  vertical-align: baseline;
  transform: translate(0, 0);
}

.reset-button::after {
  border: none;
}

</style>
